FROM golang:latest AS builder

WORKDIR /opt

COPY . .

RUN go env -w CGO_ENABLED=0
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN go mod tidy
RUN go mod download

# 构建可执行文件
RUN go build -o go_run .

FROM centos:7

RUN mkdir /app

WORKDIR /app

COPY --from=builder /opt/go_run .
COPY --from=builder /opt/*.yml .

RUN chmod +x go_run

# 暴露端口
EXPOSE 9099

# 指定容器启动时执行的命令
ENTRYPOINT ["/app/go_run"]